const pool = require('../../config/database')

class userMoels{
    async findUser(username){
        const [rows] =await pool.query(
            'SELECT * FROM company_admins WHERE username=?',[username]
        );
        console.log(rows);
        return rows;
    }

    async cerateUser(data){
        const { name,company_id,username,password } = data;
        const [rows] = await pool.query(
            'INSERT INTO company_admins (name,company_id,username,password) VALUES (?,?,?,?)',[ name,company_id,username,password ]
        );
        return {id:rows.insertId,...data};
    }

    async login(data){
        const { username } = data;
        const [rows] = await pool.execute(
            'SELECT * FROM company_admins WHERE username = ? LIMIT 1',[username]
        );
        return rows[0];
    }
}



module.exports = new userMoels();